<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计时器调用</title>
</head>
<body>
<textarea rows="5" cols="30" id="text" maxlength="140"></textarea>
<span id="box">你还可以输入140个字</span>
<script type="text/javascript">
    var text=document.getElementsByTagName('textarea');
    var box=document.getElementsByTagName('span');
    text[0].onkeyup=function(){
        var yxx=text[0].value;
        box[0].innerHTML='你还可以输入'+(140-yxx.length)+'个字符';
        if(yxx.length>=140){
            text[0].style.backgroundColor='red';
            box[0].innerHTML='你最多输入140个字';
        }
        function db(){
            text[0].style.backgroundColor="";
        }
        setTimeout(db,1000);
    }
</script>
</body>
</html>